

import java.net.Socket;
import java.net.URI;
import java.net.URISyntaxException;


/**
 * @ClassName: RTSPUtils
 * @Description: 测试RTSP连接状态
 * @Author: zhanghui
 * @Date: 2023-12-08
 * @Version: 1.0
 **/
public class RTSPUtils {
    private static final int TIMEOUT_MS = 10000; // 设置连接超时时间为10秒

    public static boolean RtspStatus(String rtspUrl) {
        try {
            URI uri = new URI(rtspUrl);
            String rtspHost = uri.getHost();
            int rtspPort = uri.getPort() != -1 ? uri.getPort() : 554; // 默认端口为554

            try (Socket socket = new Socket()) {
                socket.connect(new java.net.InetSocketAddress(rtspHost, rtspPort), TIMEOUT_MS);
                if (!socket.isConnected()) {
                    return false;
                }
                return true;
            } catch (Exception e) {
                return false;
            }
        } catch (URISyntaxException e) {
            return false;
        }
    }
    public static void main(String[] args) {
        System.out.println(RtspStatus("rtsp://admin:Langhong%402023@192.168.88.161:554/Streaming/Channels/101"));
    }
}

